﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class role_edit : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            bd();
        }
    }

    private void bd()
    {
        try
        {
            txtRoleId.Attributes.Add("readonly", "readonly");
            int id = int.Parse(Request["id"]);
            CMSModel.CMSEntities cms = DBManager.GetCmsEmtity();
            CMSModel.Role role = cms.Role.Where(x => x.RoleId == id).First();
            txtName.Text = role.RoleName;
            txtRoleId.Text = role.RoleId.ToString();
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.error).Write(GetType(), "editRole", LogYuMin.LogStates.ERROR, ex);
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('"+ex.Message+"')", true);
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(txtRoleId.Text);
            CMSModel.CMSEntities cms = DBManager.GetCmsEmtity();
            CMSModel.Role role = cms.Role.Where(x => x.RoleId == id).First();
            role.RoleName = txtName.Text;
            if (Request["aa"] == "1")
            {
                role.IsEnable = true;
            }
            else
            {
                role.IsEnable = false;
            }
            cms.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('修改成功');document.location='default.aspx'", true);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('修改失败')", true);
        }
    }
}